<template>
  <view class="clock-user">
    <!-- 无成员 -->
    <view v-if="!isShowMoreAvatar">
      <view v-if="!hasGroup" class="clock-user-noteam">
        <image
          :lazy-load="true"
          class="clock-user-noteam__item"
          :src="NO_AVATAR_DEFAULT"
        />
        <image
          :lazy-load="true"
          class="clock-user-noteam__item"
          :src="NO_AVATAR_DEFAULT"
        />
        <image
          :lazy-load="true"
          class="clock-user-noteam__item"
          :src="NO_AVATAR_DEFAULT"
        />
        <image
          :lazy-load="true"
          class="clock-user-noteam__item"
          :src="NO_AVATAR_DEFAULT"
        />
        <image
          :lazy-load="true"
          class="clock-user-noteam__item"
          :src="NO_AVATAR_DEFAULT"
        />
      </view>
      <!-- 有成员入团 -->
      <view v-else class="clock-user-hasmumber">
        <view
          v-for="user in groupUser"
          :key="user.id"
          class="clock-user-hasmumber__item"
        >
          <image
            :lazy-load="true"
            class="mumber-avatar"
            :class="mumberAvatarClassName(user)"
            :src="user.avatar"
          />
          <view v-if="user.username" class="mumber-name">
            {{ user.username }}
          </view>
          <image
            v-if="isShowRemoveButton(user)"
            :lazy-load="true"
            class="clear-icon"
            src="@/assets/icon/remove-member.png"
            @tap="handleRemoveMember(user)"
          />
        </view>
      </view>
    </view>
    <!-- 超过10个 -->
    <view v-else class="over-limit">
      <avatarGroup
        class="over-limit-avatar"
        :avatar="avatarGroups"
        :avatar-limit-len="AVATAR_MORE_LIMIT"
        :height="72"
      />
      <view class="over-limit-text">
        等已加入团队
      </view>
    </view>
  </view>
</template>
<script>
import avatarGroup from "@/components/avatar-group";
const NO_AVATAR_DEFAULT = require("@/assets/icon/no-avatar.png");
/**头像做多展示限制 */
const AVATAR_MORE_LIMIT = 10;
export default {
  components: { avatarGroup },
  props: {
    isRemoveStatus: { type: Boolean, required: true },
    /**团员信息 */
    groupUser: {
      type: Array,
      default: []
    },
    /**是否有团 */
    hasGroup: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      NO_AVATAR_DEFAULT,
      AVATAR_MORE_LIMIT
    };
  },
  computed: {
    /**已入团得头像集合 */
    avatarGroups() {
      return this.groupUser.map(i => i.avatar);
    },
    /**是否展示更多头像 */
    isShowMoreAvatar() {
      return this.groupUser.length > AVATAR_MORE_LIMIT;
    }
  },
  methods: {
    /**是否显示头部移除按钮 */
    isShowRemoveButton({ username, is_leader }) {
      return this.isRemoveStatus && username && !is_leader;
    },
    mumberAvatarClassName({ username, is_leader }) {
      return {
        "remove-flag": this.isShowRemoveButton({ username, is_leader }),
        "team-leader": !!is_leader
      };
    },
    handleRemoveMember(user) {
      this.$emit("remove", user);
    }
  }
};
</script>
<style lang="scss">
@keyframes remove-avatar {
  0% {
    transform: rotate(-4deg);
  }
  25% {
    transform: rotate(-2deg);
  }
  50% {
    transform: rotate(0deg);
  }
  75% {
    transform: rotate(2deg);
  }
  100% {
    transform: rotate(4deg);
  }
}
@import "../scss/group-common.scss";
.clock-user {
  %base-avatar {
    box-sizing: border-box;
    width: 88px;
    height: 88px;
    background-size: 100%;
    &:last-child {
      margin-right: 0;
    }
  }
  &-noteam {
    padding-left: 20px;
    position: relative;
    margin-bottom: 104px;
    display: flex;
    &__item {
      margin-right: 36px;
      @extend %base-avatar;
    }
  }
  .team-leader {
    &::after {
      content: "团长";
      position: absolute;
      left: 50%;
      bottom: 30rpx;
      transform: translateX(-50%);
      @extend %base-team-leader;
    }
  }
  &-hasmumber {
    margin-bottom: 24px;
    display: flex;
    padding-left: 16px;
    flex-wrap: wrap;
    &__item {
      margin-right: 30px;
      width: 96px;
      color: #303133;
      font-size: 24px;
      display: flex;
      align-items: center;
      flex-direction: column;
      margin-bottom: 32px;
      &:nth-child(5n) {
        margin-right: 0;
      }
      .mumber-name {
        width: 100%;
        @extend %base-one-hide;
        height: 34px;
        text-align: center;
        margin-top: 14px;
      }
      .mumber-avatar {
        border-radius: 50%;
        @extend %base-avatar;
        border: 2px solid #ffffff;
      }
      position: relative;
      .clear-icon {
        position: absolute;
        top: -4px;
        height: 28px;
        width: 28px;
        right: 4px;
      }
      .remove-flag {
        animation: remove-avatar 0.2s infinite;
        animation-direction: alternate;
      }
    }
  }
  .over-limit {
    margin-left: 4px;
    width: 100%;
    height: 120px;
    background: #fff4bb;
    border-radius: 200px;
    padding: 0 26px;
    margin-bottom: 58px;
    display: flex;
    align-items: center;
    &-avatar {
      margin-right: 10px;
    }
    &-text {
      @include base-text(40px, 28px, #a13d0f, 400);
      opacity: 1;
    }
  }
}
</style>
